package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.mapper.CheckitemMapper;
import com.itheima.mapper.SetMealCheckGroupMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckitemServiceImpl implements CheckitemService {
    @Autowired
    private CheckitemMapper checkitemMapper;
    @Autowired
    private SetMealCheckGroupMapper setMealCheckGroupMapper;
    /**
     * 新增检查项
     * @param checkItem
     * @return
     */
    @Override
    public void addItem(CheckItem checkItem) {
        checkitemMapper.addItem(checkItem);
    }
    /**
     * 根据id删除检查项
     */
    @Override
    public void deleteItem(Integer id) {
        checkitemMapper.deleteItem(id);
    }
    /**
     * 根据检查组id查询关联的检查项id
     */
    @Override
    public Integer[] findCheckItemIdsByCheckGroupId(Integer id) {
        Integer[] checkItemIds = checkitemMapper.findCheckItemIdsByCheckGroupId(id);
        return checkItemIds;
    }
    /**
     * 编辑检查项
     */
    @Override
    public void editItem(CheckItem checkItem) {
        checkitemMapper.editItem(checkItem);
    }
    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        //开启分页查询
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        //查询当前页结果
        List<CheckItem> rows = checkitemMapper.findPage();
        //查询总记录数
        Long total = checkitemMapper.countAll();
        //封装返回结果
        return new PageResult(total,rows);
    }
    /**
     * 查询所有检查项
     */
    @Override
    public List<CheckItem> findAll() {
        List<CheckItem> rows = checkitemMapper.findPage();
        return rows;
    }
    /**
     * 根据id查询检查项
     */
    @Override
    public CheckItem findById(Integer id) {
        CheckItem checkItem = checkitemMapper.findById(id);
        return checkItem;
    }

    /**
     * 根据套餐id查询关联的检查项id
     */
    @Override
    public List<Integer> findCheckGroupIdsBySetmealId(Integer id) {
        List<Integer> checkItemId = setMealCheckGroupMapper.findCheckGroupIdsBySetmealId(id);
        return checkItemId;
    }
}
